Page({
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData=' + this.data.passport.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  data: {
    passport: {},
  },

  // 进入这个页面有两种人 一种就是业主  一种是访客
  onLoad({ id, encryptedData }) {
    id && this.getPassportInfo(id) // 登录用户访问
    // encryptedData 游客 取这个字段进行访问
    encryptedData && this.getShareInfo(encryptedData)
  },
  // 获取邀请的详情  业主访问
  async getPassportInfo(id) {
    const { data: passport } = await wx.http.get(`/visitor/${id}`)
    this.setData({ passport })
  },

  // 获取邀请的详情   访客访问
  async getShareInfo(encryptedData) {
    const { data: passport } = await wx.http.get(`/visitor/share/${encryptedData}`)
    this.setData({ passport })
  },

  // 保存图片到本地相册
  async saveImg() {
    try {
      // 配置服务器 download url
      const res1 = await wx.getImageInfo({ src: this.data.passport.url })
      // console.log(res1.path) // 临时路径
      await wx.saveImageToPhotosAlbum({
        filePath: res1.path,
      })
    } catch (error) {}
  },
})
